-- 创建系统管理员表
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[S_Admin]') AND type in (N'U')) DROP TABLE [dbo].[S_Admin];
CREATE TABLE [dbo].[S_Admin](
    Id INT NOT NULL IDENTITY(1,1),
    Account NVARCHAR(50) DEFAULT  N'',
    Salt NVARCHAR(50),
    Password NVARCHAR(50) DEFAULT  N'',
    Nickname NVARCHAR(50) DEFAULT  N'',
    IsSuper INT,
    Token NVARCHAR(50),
    TokenExpireTime datetime,
    CreateTime datetime DEFAULT  0,
    CreaterId INT,
    IsDelete INT,
    DeleteTime datetime,
    DeleterId INT,
    PRIMARY KEY (Id)
);
EXEC sp_addextendedproperty 'MS_Description', '系统管理员表', 'SCHEMA', dbo, 'table', S_Admin, null, null;
EXEC sp_addextendedproperty 'MS_Description', '识别号', 'SCHEMA', dbo, 'table', S_Admin, 'column', Id;
EXEC sp_addextendedproperty 'MS_Description', '登录账号', 'SCHEMA', dbo, 'table', S_Admin, 'column', Account;
EXEC sp_addextendedproperty 'MS_Description', '盐值', 'SCHEMA', dbo, 'table', S_Admin, 'column', Salt;
EXEC sp_addextendedproperty 'MS_Description', '登录密码', 'SCHEMA', dbo, 'table', S_Admin, 'column', Password;
EXEC sp_addextendedproperty 'MS_Description', '昵称', 'SCHEMA', dbo, 'table', S_Admin, 'column', Nickname;
EXEC sp_addextendedproperty 'MS_Description', '是否超级管理员', 'SCHEMA', dbo, 'table', S_Admin, 'column', IsSuper;
EXEC sp_addextendedproperty 'MS_Description', '令牌', 'SCHEMA', dbo, 'table', S_Admin, 'column', Token;
EXEC sp_addextendedproperty 'MS_Description', '失效时间', 'SCHEMA', dbo, 'table', S_Admin, 'column', TokenExpireTime;
EXEC sp_addextendedproperty 'MS_Description', '创建时间', 'SCHEMA', dbo, 'table', S_Admin, 'column', CreateTime;
EXEC sp_addextendedproperty 'MS_Description', '创建人', 'SCHEMA', dbo, 'table', S_Admin, 'column', CreaterId;
EXEC sp_addextendedproperty 'MS_Description', '是否删除', 'SCHEMA', dbo, 'table', S_Admin, 'column', IsDelete;
EXEC sp_addextendedproperty 'MS_Description', '删除时间', 'SCHEMA', dbo, 'table', S_Admin, 'column', DeleteTime;
EXEC sp_addextendedproperty 'MS_Description', '删除人', 'SCHEMA', dbo, 'table', S_Admin, 'column', DeleterId;

-- 插入超级管理员
INSERT INTO [dbo].[S_Admin] (Account, Salt, Password, Nickname, IsSuper, Token, TokenExpireTime, CreateTime, CreaterId, IsDelete, DeleteTime, DeleterId) 
VALUES ('super', 'w2o0u0', '6d85ab30f06970e82b3cfa24ae065bc8', '超人', 1, '', NULL, GETDATE(), 0, 0, NULL, NULL);

-- 插入测试账号
INSERT INTO [dbo].[S_Admin] (Account, Salt, Password, Nickname, IsSuper, Token, TokenExpireTime, CreateTime, CreaterId, IsDelete, DeleteTime, DeleterId) 
VALUES ('test', '', '', '测试', 0, '123456', '2055-12-31 23:59:59', GETDATE(), 0, 0, NULL, NULL);

-- 创建管理员角色表
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[S_AdminRole]') AND type in (N'U')) DROP TABLE [dbo].[S_AdminRole];
CREATE TABLE [dbo].[S_AdminRole](
    Id INT NOT NULL IDENTITY(1,1),
    AdminID INT DEFAULT  0,
    RoleID INT DEFAULT  0,
    Marker INT DEFAULT  0,
    PRIMARY KEY (Id)
);
EXEC sp_addextendedproperty 'MS_Description', '管理员角色对应表', 'SCHEMA', dbo, 'table', S_AdminRole, null, null;
EXEC sp_addextendedproperty 'MS_Description', '识别号', 'SCHEMA', dbo, 'table', S_AdminRole, 'column', Id;
EXEC sp_addextendedproperty 'MS_Description', '操作员', 'SCHEMA', dbo, 'table', S_AdminRole, 'column', AdminID;
EXEC sp_addextendedproperty 'MS_Description', '角色', 'SCHEMA', dbo, 'table', S_AdminRole, 'column', RoleID;
EXEC sp_addextendedproperty 'MS_Description', '标记', 'SCHEMA', dbo, 'table', S_AdminRole, 'column', Marker;
